#!/usr/bin/perl
# diskswap.cgi in diskman

require './diskman-lib.pl';

&ReadParse();

my ($index, $scsiid, $sysvol_at, $userpart, $sysvpart);

# set default value
$sysvol_at=$hwinfo{'sysvol_at'};
$userpart =$hwinfo{'userpart'};
$sysvpart =$hwinfo{'sysvpart'};
$markpart =$hwinfo{'markpart'};
if(!$sysvol_at) { $sysvol_at=0; }
if(!$sysvpart)  { $sysvpart =1; }
if(!$userpart)  { $userpart =5; }
if(!$markpart)  { $markpart =6; }


my $diskname=$in{'disk'};
@rdinfo=new_get_check_raid_info();
@dinfo=new_get_diskinfo(\@rdinfo);

#get disk info
my $found=0;
my %disk;

foreach $d (@dinfo) {
	if ($d->{'device'} eq $diskname) { 
		$found=1;
		%disk=%{$d};
		last;
	}
}
if(!$found) {
	$err_msg = $text{'err_cgiparam'};
	goto ERROR_OUT;
}

$cmd_line = $config{'amccpath'}.' /c0/'.$diskname.' export quiet 2>/dev/null';
$out = `$cmd_line`;
if($?){
   $res = 0;
}
else{
   $res = 1;
}

#&redirect("index.cgi");
#-----------------------------------------------------------------
&header("disk swap", "");
print "<form name=recoveryform action=3w_disk_rescan.cgi method=post>\n";
$diskname =~ /^p(\d+)/;
$dname = "Disk".($1+1);
if($res == 1){
   print "<p>$dname $text{'diskswap_one'}</p>\n";
   print "<p>$text{'diskswap_two'}</p>\n";
   print "<p>$text{'diskswap_three'}</p>\n";
   print "<p>$text{'diskswap_four'}</p>\n";
}else
{
   print "<p> $diskname remove failed!</p>\n";
}
print "<input type=submit name=back value=OK class=button1>\n";
print "</form>\n";
&footer("");
#-----------------------------------------------------------------
return;

ERROR_OUT:
&error_setup("");
&error($err_msg);

